package vip.ablog.xmall.product.controller;

import java.util.Arrays;
import java.util.Map;

//
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import vip.ablog.xmall.product.entity.AttrEntity;
import vip.ablog.xmall.product.service.AttrService;
import vip.ablog.common.utils.PageUtils;
import vip.ablog.common.utils.R;
import vip.ablog.xmall.product.vo.AttrResponseVo;
import vip.ablog.xmall.product.vo.AttrVo;


/**
 * 商品属性
 *
 * @author jsp
 * @email jsp@gmail.com
 * @date 2020-08-10 17:11:08
 */
@RestController
@RequestMapping("product/attr")
public class AttrController {
    @Resource
    private AttrService attrService;

    @GetMapping("/{attrType}/list/{catelogId}")
    public R baseAttrList(@RequestParam Map<String, Object> params,
                          @PathVariable("catelogId") Long catelogId,
                          @PathVariable("attrType")String attrType){
        PageUtils page =  attrService.queryBaseAttrPage(params, catelogId, attrType);
        return R.ok().put("page", page);
    }

/*    @GetMapping("/base/list/{catelogId}")
    public R baseAttrList(@RequestParam Map<String, Object> params,
                          @PathVariable("catelogId") Long catelogId){
        PageUtils page =  attrService.queryBaseAttrPage(params, catelogId);
        return R.ok().put("page", page);
    }*/

    /**
     * 列表
     */
    @RequestMapping("/list")
    ////@RequiresPermissions("product:attr:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = attrService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{attrId}")
    ////@RequiresPermissions("product:attr:info")
    public R info(@PathVariable("attrId") Long attrId){
		AttrResponseVo responseVo = attrService.getAttrInfo(attrId);

        return R.ok().put("attr", responseVo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    ////@RequiresPermissions("product:attr:save")
    public R save(@RequestBody AttrVo attr){
		attrService.saveAttr(attr);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
   // //@RequiresPermissions("product:attr:update")
    public R update(@RequestBody AttrVo attr){
		attrService.updateAttr(attr);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
  //  //@RequiresPermissions("product:attr:delete")
    public R delete(@RequestBody Long[] attrIds){
		attrService.removeByIds(Arrays.asList(attrIds));

        return R.ok();
    }

}
